package com.turnengine.client.local.player.command.gwt;

import static com.javabi.common.dependency.DependencyFactory.getDependency;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.javabi.codebuilder.generated.gwt.IGeneratedRemoteServiceServlet;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.errorcode.gwt.GwtErrorCodeException;
import com.javabi.command.executor.ICommandExecutorService;
import com.turnengine.client.local.player.bean.IPlayer;
import com.turnengine.client.local.player.command.GetPlayerByUserId;

/**
 * The Get Player By User Id Servlet.
 */
public class GetPlayerByUserIdServlet extends RemoteServiceServlet implements IGeneratedRemoteServiceServlet, GetPlayerByUserIdService {

	public IPlayer getPlayerByUserId(long loginId, int instanceId, int id) throws GwtErrorCodeException {
		GetPlayerByUserId command = new GetPlayerByUserId(loginId, instanceId, id);
		ICommandExecutorService service = getDependency(ICommandExecutorService.class);
		IExecutableCommandResponse<IPlayer> response = service.execute(command);
		if (response.hasErrors()) {
			throw new GwtErrorCodeException(response);
		}
		return response.getReturnValue();
	}
}
